<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<h2 mat-dialog-title>{{ isUpdate ? 'Edit a tag' : 'Create a tag' }}</h2>

<gio-banner-info>Sharding tag can be restricted to some groups to only allow users of these groups to deploy on this tag.</gio-banner-info>

<form autocomplete="off" [formGroup]="tagForm" (ngSubmit)="onSubmit()">
  <mat-dialog-content>
    <div class="form">
      <mat-form-field appearance="fill">
        <mat-label>Name</mat-label>
        <input matInput formControlName="name" required />
        <mat-hint align="end">{{ tagForm.get('name').value?.length ?? 0 }}/64</mat-hint>
        <mat-error *ngIf="tagForm.get('name').hasError('maxlength')">Name has to be less than 64 characters long.</mat-error>
        <mat-error *ngIf="tagForm.get('name').hasError('minlength')">Name has to be more than 2 characters long.</mat-error>
        <mat-error *ngIf="tagForm.get('name').hasError('required')">Name is required.</mat-error>
      </mat-form-field>

      <mat-form-field appearance="fill">
        <mat-label>Description</mat-label>
        <input matInput formControlName="description" />
      </mat-form-field>

      <mat-form-field appearance="fill">
        <mat-label>Restricted groups</mat-label>
        <mat-select formControlName="restrictedGroups" aria-label="Restricted groups selection" multiple>
          <mat-option *ngFor="let group of groups$ | async" [value]="group.id">{{ group.name }}</mat-option>
        </mat-select>
      </mat-form-field>
    </div>
  </mat-dialog-content>

  <mat-dialog-actions class="actions">
    <button mat-button [mat-dialog-close]="false">Cancel</button>
    <button mat-button [disabled]="tagForm.invalid" type="submit">Ok</button>
  </mat-dialog-actions>
</form>
